home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / lang / HeliOS3.lha / helios_demo_disk3 / source / Demo6_SimpleAnim.src < prev    next >
Encoding:
Text File  |  1995-11-11  |  27.5 KB  |  971 lines

  1.  
  2.   \ ***********************************************************
  3.   \
  4.   \                    SIMPLE ANIMATION DEMO
  5.   \
  6.   \ ***********************************************************
  7.   \
  8.   \ This code demonstrates how to create a simple animation
  9.   \ in HeliOS.
  10.   \
  11.   \ This builds upon the following Demos:
  12.   \
  13.   \ Demo1_SinglePF.src
  14.   \ Demo2_SinglePFCopper.src
  15.   \ Demo3_SimpleSprite.src
  16.   \ Demo4_MultiSprites.src
  17.   \ Demo5_MultiSptCollide.src
  18.   \
  19.   \ This code is then expanded in the following Demos:
  20.   \
  21.   \ Demo7_MultiAnim.src
  22.   \
  23.   \ ***********************************************************
  24.  
  25.  
  26.  
  27.   \ ***********************************************************
  28.   \ Re-initialise HeliOS dictionary to standard CORE vocabulary
  29.   \ ***********************************************************
  30.  
  31.   \ This should always be used at the start of any program which
  32.   \ is to be repeatedly recompiled.
  33.  
  34.   FORGET **CORE**
  35.  
  36.   \ *************************
  37.   \ Load include symbol files
  38.   \ *************************
  39.   \
  40.   \ These "include files" are pre-compiled (for speed) versions of the
  41.   \ Amiga includes and the Helios system includes.
  42.   \
  43.   \ Uncomment the lines below for standalone compilation, but otherwise
  44.   \ it is better to set these include files from the Helios Forth menus
  45.  
  46.   AMIGAINCLUDE HeliOS:HeliOS_AmigaInclude
  47.   USERINCLUDE  HeliOS:HeliOS_UserInclude
  48.  
  49.   \ ****************************************
  50.   \ Create display imagery file name strings
  51.   \ ****************************************
  52.  
  53.   \ These files are ordinary IFF's (and may be "PowerPacked" if required)
  54.   \
  55.   \ The pictures here will be loaded into each of the display BitMaps.
  56.   \
  57.  
  58.   $CONSTANTL Slice1Pic $Helios:Source/Data/Pic1$
  59.  
  60.   \ **************************************
  61.   \ Create display configuration constants
  62.   \ **************************************
  63.   \
  64.   \ Collect all "display-specific" parameters here and generate "named"
  65.   \ constants which make references easier than using numeric values.
  66.   \
  67.   \ Collecting these together here makes it easier to adjust things at any
  68.   \ time without having to search source code to replace values individually.
  69.   \
  70.  
  71.  
  72.   256                      CONSTANT DisplayHeight      \ Full PAL display
  73.   320                      CONSTANT DisplayWidth       \ Lores display
  74.   44                       CONSTANT DisplayTopLine     \ Display start
  75.  
  76.   DisplayWidth             CONSTANT Slice1Width        \ Lores width
  77.   DisplayWidth 32 +        CONSTANT Slice1RasterWidth  \ Raster=SWidth+32
  78.   DisplayHeight            CONSTANT Slice1Height       \ Slice height
  79.   DisplayHeight 32 +       CONSTANT Slice1RasterHeight \ Slice Raster=DHgt+32
  80.   0                        CONSTANT Slice1Mode         \ Lores
  81.   3                        CONSTANT Slice1Planes       \ Slice bitplanes
  82.  
  83.   \ The calculation below takes the number of bitplanes and calculates
  84.   \ how many colours this represents.
  85.   \
  86.   \ One bitplane gives two colours.
  87.   \
  88.   \ Each additional bitplane multiplies the number of colours by two.
  89.   \
  90.   \ Performing a single LSL operation on any number multipies by 2, so we
  91.   \ have a quick method of multiplying by two for our colour calculation.
  92.   \
  93.   \ In this case, we need "2 to the power 3", which is 2*2*2=8.
  94.   \
  95.   \ e.g.                              2*2*2
  96.   \                                   ^ ^ ^
  97.   \                                   Total number of planes = 3
  98.   \
  99.   \
  100.   \ So, we take the first value two
  101.   \
  102.   \ e.g.                              2*2*2
  103.   \                                   ^
  104.   \                                  Initial start value of 2
  105.   \
  106.   \ and we now need to multiply it by two "the_number_of_planes minus_one"
  107.   \ more times.
  108.   \
  109.   \ e.g.                              2*2*2
  110.   \                                     ^ ^
  111.   \                                     Total planes minus one
  112.   \
  113.   \
  114.   \ So, Number of colours = 2 operated on by LSL NumberOfPlanes-1 times.
  115.   \
  116.  
  117.   2 Slice1Planes 1- LSL    CONSTANT Slice1Colours      \ A-slice colours
  118.  
  119.   \ ***********************
  120.   \ Error handling routines
  121.   \ ***********************
  122.  
  123.   \ This error handler allows all errors to be routed via a comprehensive
  124.   \ sequential closedown routine, which is associated with the HeliOS
  125.   \ system error handler word ERROR".
  126.   \
  127.   \ When ERROR" senses an error, it prints an associated error message
  128.   \ delimited by '"' characters, and then closes everything down using the
  129.   \ routine CLOSEDOWN below which you have supplied.
  130.   \
  131.   \ This simplifies errors checks to the use of a single word, ERROR", which
  132.   \ displays a text message and closes eveything down.
  133.   \
  134.  
  135.   0 VARIABLE (CLOSEDOWN)
  136.  
  137.   : ?CLOSEDOWNERROR
  138.  
  139.   IF
  140.     CR
  141.     CR
  142.     TYPE
  143.     CR
  144.     CR
  145.     ." Press <Space> to quit!"
  146.     CR
  147.     CR
  148.     WAITSPACE
  149.     (CLOSEDOWN) @EXECUTE
  150.     QUIT
  151.   ELSE
  152.     DDROP
  153.   THEN
  154.   ;
  155.  
  156.   LATESTCFA VARIABLE ERROR1
  157.  
  158.   \ ****************************************
  159.   \ Create display pointer storage variables
  160.   \ ****************************************
  161.  
  162.   \ Here we create a set of "pointers", initially set to a "null" value.
  163.   \
  164.   \ These "pointers" are set up as "long addresses" when various components
  165.   \ of the display system are allocated and initialised.
  166.   \
  167.   \ Note that initially these are all set to zero, and we clear them back
  168.   \ to zero when we de-allocate the associated resource.
  169.   \
  170.   \ These DPOINTERs are all initially set to "null" by using '0.'.
  171.   \
  172.   \ When we allocate memory or Amiga system resources in the program at
  173.   \ run-time, these pointers are updated to contain the 32-bit address
  174.   \ of the newly allocated resource.
  175.   \
  176.   \ Subsequently the symbolic DPOINTER name can be used in your code to
  177.   \ represent the associated address.
  178.  
  179.   0. DPOINTER Display1             \ Main Display structure pointer
  180.   0. DPOINTER Slice1               \ Slice 1 Slice structure pointer
  181.  
  182.   0. DPOINTER Slice1_ColorMap      \ Slice 1 ColourMap structure pointer
  183.  
  184.   0. DPOINTER Slice1_RasInfo       \ Slice 1 RasInfo structure pointer
  185.  
  186.   0. DPOINTER Slice1_BMap          \ Slice 1 BitMap structure pointer
  187.  
  188.   0. DPOINTER Slice1_SliceControl  \ Slice 1 SliceControl structure pointer
  189.  
  190.   \ *************
  191.   \ Colour tables
  192.   \ *************
  193.  
  194.   \ Each colour entry requies 2 bytes of storage space
  195.  
  196.   CREATEL Slice1_ColorTable        \ Create longword pointer to table
  197.   Slice1Colours 2* 0 ALLOTFILL     \ Allocate Slice1 colours * 2 bytes
  198.  
  199.  
  200.   \ *************************************
  201.   \ Copper strip for graduated background
  202.   \ *************************************
  203.  
  204.   0. DVARIABLE Copper              \ 32-bit CopperList pointer store
  205.   0. DVARIABLE CopperLength        \ 32-bit CopperList length store
  206.  
  207.   : AddCopper                      \ Add custom copper list to display
  208.  
  209.   Display1                         \ We are adding CopperList to Display1
  210.   Copper D@
  211.   ADDCOPPERSTRIP
  212.   SORTSTRIPTABLE
  213.   LINKSTRIPS
  214.   DDROP
  215.   ;
  216.  
  217.   : RemCopper                      \ Remove custom copper list from display
  218.  
  219.   Display1                         \ We are removing CopperList from Display1
  220.   Copper D@
  221.   DFLAG
  222.   IF
  223.     REMCOPPERSTRIP
  224.     LINKSTRIPS
  225.     DDROP
  226.   ELSE
  227.     DDDROP
  228.   THEN
  229.   ;
  230.  
  231.   : Create_Copper
  232.  
  233.   COPPERSTART
  234.   Copper D!
  235.   0 [ DECIMAL ]  45 [ HEX ] FFFE COPPERWAIT  DROP   0100 18E COPPERMOVE  DROP
  236.   0 [ DECIMAL ]  60 [ HEX ] FFFE COPPERWAIT  DROP   0200 18E COPPERMOVE  DROP
  237.   0 [ DECIMAL ]  75 [ HEX ] FFFE COPPERWAIT  DROP   0300 18E COPPERMOVE  DROP
  238.   0 [ DECIMAL ]  90 [ HEX ] FFFE COPPERWAIT  DROP   0400 18E COPPERMOVE  DROP
  239.   0 [ DECIMAL ] 105 [ HEX ] FFFE COPPERWAIT  DROP   0500 18E COPPERMOVE  DROP
  240.   0 [ DECIMAL ] 120 [ HEX ] FFFE COPPERWAIT  DROP   0600 18E COPPERMOVE  DROP
  241.   0 [ DECIMAL ] 135 [ HEX ] FFFE COPPERWAIT  DROP   0700 18E COPPERMOVE  DROP
  242.   0 [ DECIMAL ] 150 [ HEX ] FFFE COPPERWAIT  DROP   0800 18E COPPERMOVE  DROP
  243.   0 [ DECIMAL ] 165 [ HEX ] FFFE COPPERWAIT  DROP   0900 18E COPPERMOVE  DROP
  244.   0 [ DECIMAL ] 180 [ HEX ] FFFE COPPERWAIT  DROP   0A00 18E COPPERMOVE  DROP
  245.   0 [ DECIMAL ] 195 [ HEX ] FFFE COPPERWAIT  DROP   0B00 18E COPPERMOVE  DROP
  246.   0 [ DECIMAL ] 210 [ HEX ] FFFE COPPERWAIT  DROP   0C00 18E COPPERMOVE  DROP
  247.   0 [ DECIMAL ] 225 [ HEX ] FFFE COPPERWAIT  DROP   0D00 18E COPPERMOVE  DROP
  248.   0 [ DECIMAL ] 240 [ HEX ] FFFE COPPERWAIT  DROP   0E00 18E COPPERMOVE  DROP
  249.   0 [ DECIMAL ] 255 [ HEX ] FFFE COPPERWAIT  DROP   0F00 18E COPPERMOVE  DROP
  250.   [ DECIMAL ]
  251.   COPPEREND
  252.   CopperLength D!   Copper D!
  253.   ADDCOPPER
  254.   ;
  255.  
  256.   : Free_Copper                  \ Closes down and frees copperlist memory
  257.  
  258.   RemCopper
  259.   Copper D@ FREEMEMORY
  260.   ;
  261.  
  262.   \ ***********************************
  263.   \ Create Display and Slice structures
  264.   \ ***********************************
  265.  
  266.   \ This routine simply makes blank structures, which then need to be
  267.   \ initialised later (in the CREATE_DISPLAY routine).
  268.  
  269.   : CREATE_DSLICES
  270.  
  271.   DS_SIZEOF MAKESTRUCTURE Display1 MAKEPOINTER  \ Main "Display" structure
  272.  
  273.   SL_SIZEOF MAKESTRUCTURE Slice1   MAKEPOINTER  \ Display "Slice" structure
  274.   ;
  275.  
  276.   : FREE_DSLICES
  277.  
  278.   Slice1    DDUP FREEMEMORY   CLEARPOINTER
  279.   Display1  DDUP FREEMEMORY   CLEARPOINTER
  280.   ;
  281.  
  282.   \ ******************************
  283.   \ Create RasInfo structures etc.
  284.   \ ******************************
  285.  
  286.   : CREATE_RASINFO
  287.  
  288.   \ First allocate and initialise complete RasInfo structures.
  289.   \
  290.   \ This routine automatically allocates all BitMaps etc.
  291.   \
  292.  
  293.   Slice1RasterWidth Slice1RasterHeight Slice1Planes  OPENRASINFO
  294.   DFLAG0= ERROR" Fail: RasInfo1"
  295.   Slice1_RasInfo MAKEPOINTER
  296.  
  297.   \ Set invisible area "sprite margins" for slice RasInfo
  298.  
  299.   16              Slice1_RasInfo         ri_RxOffset    INDEX!L
  300.   16              Slice1_RasInfo         ri_RyOffset    INDEX!L
  301.  
  302.   \ Store BitMap pointer - often useful for later reference
  303.  
  304.   Slice1_RasInfo  ri_BitMap INDEXD@L Slice1_BMap MAKEPOINTER
  305.   ;
  306.  
  307.   : FREE_RASINFO
  308.  
  309.   Slice1_RasInfo   DDUP CLOSERASINFO   CLEARPOINTER
  310.   ;
  311.  
  312.   \ ********************************
  313.   \ Create Display/Slice Copperlists
  314.   \ ********************************
  315.  
  316.   \ This function builds the main display copperlist by:
  317.   \
  318.   \ 1. Initialising the Slice data structure
  319.   \ 2. Calling MAKECOPSTRIP for the slice, to build a copperlist
  320.   \ 3. Calling MAKEDISPLAY to build the master Display copperlist
  321.   \
  322.  
  323.   : CREATE_DISPLAY
  324.  
  325.   \ First initialise main display structures
  326.  
  327.   Slice1                           Display1  DS_Slice     INDEXD!L
  328.  
  329.   Slice1Width                      Slice1    SL_DWidth    INDEX!L
  330.   Slice1Height                     Slice1    SL_DHeight   INDEX!L
  331.   DisplayTopLine                   Slice1    SL_DyOffset  INDEX!L
  332.   Slice1_RasInfo                   Slice1    SL_RasInfo   INDEXD!L
  333.   Slice1_ColorMap                  Slice1    SL_ColorMap  INDEXD!L
  334.   Slice1Mode                       Slice1    SL_Modes     INDEX!L
  335.  
  336.   \ Generate copper list information for each of the display slices
  337.  
  338.   Slice1 MAKECOPSTRIP
  339.   D0= ERROR" Fail: Slice1CopStrip"
  340.  
  341.   \ Make display
  342.  
  343.   Display1 MAKEDISPLAY
  344.   D0= ERROR" Fail: Display1"
  345.   ;
  346.  
  347.   : FREE_DISPLAY
  348.  
  349.   Display1                 FREEDISPLAY
  350.   Slice1                   FREECOPSTRIP
  351.   ;
  352.  
  353.   \ ********************************************************
  354.   \ Create SliceControl structures for double buffered slice
  355.   \ ********************************************************
  356.  
  357.   \ SliceControl structures are used to control any slices which perform
  358.   \ mapping or scrolling functions, or which require double or triple
  359.   \ playfield buffering.
  360.   \
  361.   \ In this case we have one slice which does not scroll, is not mapped,
  362.   \ but IS double buffered.
  363.   \
  364.  
  365.   : CREATE_SLICECONTROL
  366.  
  367.   \ Make SliceControl for double buffered bitmap display
  368.  
  369.   Slice1  0 0 MAKESLICECONTROL
  370.   DFLAG0= ERROR" Fail: SliceControl1"
  371.   Slice1_SliceControl MAKEPOINTER
  372.  
  373.   \ Install slice controls into HeliOS display control system
  374.  
  375.   Slice1_SliceControl  INSTALLSLICECONTROL
  376.   ;
  377.  
  378.   : FREE_SLICECONTROL
  379.  
  380.   CLEARSLICECONTROLS
  381.   Slice1_SliceControl  CLOSESLICECONTROL
  382.   ;
  383.  
  384.   \ These routines load an IFF picture into supplied BitMap, and correctly
  385.   \ initialises the supplied ColorTable.
  386.   \
  387.   \ The ColorTable is then used to create an initialised ColorMap structure.
  388.   \
  389.  
  390.   : CREATE_IMAGERY
  391.  
  392.   Slice1_BMap
  393.   Slice1_ColorTable
  394.   Slice1Pic
  395.   10 2 DOSLIB                        \ Call to internal HeliOS library
  396.   10 <> ERROR" Fail: Slice1Pic"
  397.  
  398.   Slice1_ColorTable  Slice1Colours MAKECOLORMAP  \ Allocate ColourMap
  399.   DFLAG0= ERROR" Fail: Slice1ColorMap"
  400.   Slice1_ColorMap MAKEPOINTER
  401.   ;
  402.  
  403.   : FREE_IMAGERY
  404.  
  405.   Slice1_ColorMap  DDUP FREECOLORMAP  CLEARPOINTER
  406.   ;
  407.  
  408.   \ **************
  409.   \ Animation Demo
  410.   \ **************
  411.  
  412.   \ ************************
  413.   \ Animation Demo constants
  414.   \ ************************
  415.  
  416.   \ Set up a number of constants which determine various aspects of the
  417.   \ demo, e.g. How many Bullets required
  418.   \
  419.   \ Change these values as required
  420.   \
  421.  
  422.   25 CONSTANT Bullet#           \ Number of Bullets available
  423.   8  CONSTANT BulletSpeed       \ Speed of Bullet
  424.   6  CONSTANT FiringRate        \ Speed of gun reload
  425.   4  CONSTANT GunSpeed          \ Speed of Gun movement
  426.   8  CONSTANT AlienMaxXSpeed    \ Maximum speed of Alien movement
  427.   4  CONSTANT AlienMaxYSpeed    \ Maximum speed of Alien movement
  428.  
  429.   \ ****************************************************
  430.   \ Create animation demo pointers and storage variables
  431.   \ ****************************************************
  432.  
  433.   0. DPOINTER GunSpriteSet         \ Gun sprite image
  434.   0. DPOINTER BulletSpriteSet      \ Bullet sprite image
  435.   0. DPOINTER AlienSpriteSet       \ Alien sprite images
  436.   0. DPOINTER AlienAnim            \ Alien animation
  437.  
  438.   CREATE BulletTable               \ Bullet sprite pointer storage table.
  439.   Bullet# 4* 0 ALLOTFILL           \ Space allocated = Number_of_Bullets*4
  440.                                    \ This table has to hold a number of
  441.                                    \ 32-bit (4-byte) numbers, because
  442.                                    \ each Bullet sprite is a 32-bit pointer
  443.  
  444.   CREATE  BulletCollHandlerTable   \ Bullet collision handler table
  445.   Bullet# 4* 0 ALLOTFILL
  446.  
  447.   0.  DVARIABLE  AlienCollHandler  \ Alien collision handler pointer
  448.   0 VARIABLE     FireTimer         \ Gun reload rate store
  449.  
  450.  \ **************************************************
  451.  \ This routine is called to delay the Alien's return
  452.  \ **************************************************
  453.  
  454.   : AlienDelay
  455.  
  456.   DDROP                                            \ Drop Alien pointer
  457.   50  SpriteAnim_CountDown   AlienAnim INDEX!L     \ Wait 50 VBlanks
  458.   0   SpriteAnim_CDForth     AlienAnim INDEX!L     \ Remove CD action word
  459.   -3  SpriteAnim_CDFlags     AlienAnim INDEX!L     \ -3 = Remove
  460.   ;
  461.  
  462.   \ *************************
  463.   \ Sprite collision routines
  464.   \ *************************
  465.  
  466.   \ This routine is called when a Bullet collides.
  467.  
  468.   : BulletHit
  469.  
  470.   2 DDROPS                        \ Drop collisionmask and hit-object pointer
  471.  
  472.   DDUP SpriteCtrl_CollFlag D+ 0!L \ Disable further collisions
  473.   REMOVESPRITE                    \ Remove Bullet
  474.   ;
  475.  
  476.   \ This routine is called when the Alien collides.
  477.  
  478.   : AlienHit
  479.  
  480.   3 DDROPS     \ Drop collisionmask, "hitting" object, and object pointers
  481.  
  482.   0   SpriteAnim_CollFlag    AlienAnim INDEX!L  \ Disable further collisions
  483.   0   SpriteAnim_UserData1   AlienAnim INDEX!L  \ Stop X-movement (inc = 0)
  484.   0   SpriteAnim_UserData2   AlienAnim INDEX!L  \ Stop Y-movement (inc = 0)
  485.   2   SpriteAnim_Speed       AlienAnim INDEX!L  \ Set explosion anim speed
  486.   9   SpriteAnim_Frames      AlienAnim INDEX!L  \ Number of frames
  487.   0   SpriteAnim_Current     AlienAnim INDEX!L  \ Start at frame 0
  488.   20  SpriteAnim_CountDown   AlienAnim INDEX!L  \ Run for 20 VBlanks
  489.   -2  SpriteAnim_CDFlags     AlienAnim INDEX!L  \ Flags set after CountDown
  490.                                                 \ -2 = Go invisible
  491.  
  492.   ' AlienDelay  CFA                             \ Get pointer to delay code
  493.       SpriteAnim_CDForth     AlienAnim INDEX!L  \ Countdown code
  494.   ;
  495.  
  496.   \ ***************************
  497.   \ Create HitMasks and MeMasks
  498.   \ ***************************
  499.  
  500.   \ Collisions can only occur between objects which have coincident bits
  501.   \ set in HitMask-MeMask or MeMask-HitMask pairs
  502.   \
  503.   \ Each bit of the HitMask/MeMask pair have a corresponding position in
  504.   \ a collision table which stores an array of collision routines.
  505.   \
  506.   \ In the event of a collision, the routine in an object's Collision Table
  507.   \ corresponding to the HitMask-MeMask bit coincidence will be called
  508.   \ with 3 parameters: the two colliding objects and the collision HitMask
  509.   \
  510.   \ The stack on a collision call looks like this:
  511.   \
  512.   \ CollisionHitMask(l) = Top 32-bit value on stack
  513.   \ CollidingObject(l)  = 2nd 32-bit value on stack
  514.   \ This Object(l)      = 3rd 32-bit value on stack
  515.   \
  516.   \ Here are two examples:
  517.   \
  518.   \   00000000000000000000000000000010.  = Object A HitMask
  519.   \   00000000000000000000000000000000.  = Object B HitMask
  520.   \   00000000000000000000000000000001.  = Object C HitMask
  521.   \
  522.   \   00000000000000000000000000000000.  = Object A MeMask
  523.   \   00000000000000000000000000000011.  = Object B MeMask
  524.   \   00000000000000000000000000000000.  = Object C MeMask
  525.   \
  526.   \ Would allow A and B to collide, B and C to collide, but not A and C.
  527.   \
  528.   \ B and C would run the routine at position 1 in the collision table
  529.   \ A and B would run the routine at position 2 in the collision table
  530.   \
  531.   \ -----------------------------------------------------------
  532.   \
  533.   \   00000000000000000000000000000011.  = Object A HitMask
  534.   \   00000000000000000000000000000001.  = Object B HitMask
  535.   \   00000000000000000000000000000001.  = Object C HitMask
  536.   \
  537.   \   00000000000000000000000000000000.  = Object A MeMask
  538.   \   00000000000000000000000000000000.  = Object B MeMask
  539.   \   00000000000000000000000000000010.  = Object C MeMask
  540.   \
  541.   \ Would allow just A and C to collide
  542.   \
  543.   \ A and C would run the routine at position 2 in the collision table
  544.   \
  545.  
  546.   BIN
  547.  
  548.   00000000000000000000000000000001.  DCONSTANT  BulletHitMask
  549.   00000000000000000000000000000000.  DCONSTANT  AlienHitMask
  550.  
  551.   00000000000000000000000000000000.  DCONSTANT  BulletMeMask
  552.   00000000000000000000000000000001.  DCONSTANT  AlienMeMask
  553.  
  554.   DECIMAL
  555.  
  556.  
  557.   CREATEL BulletCollTable
  558.   -1 ,                        \ -1 = The "1" means there is 1 entry in table
  559.                               \      The "-" signifies that it is a HeliOS
  560.                               \      word rather than machine code
  561.  
  562.   FIND BulletHit ,            \ Find BulletHit and store HeliOS word CFA
  563.  
  564.   CREATEL AlienCollTable
  565.   -1 ,                        \ -1 = The "1" means there is 1 entry in table
  566.                               \      The "-" signifies that it is a HeliOS
  567.                               \      word rather than machine code
  568.  
  569.   FIND AlienHit ,             \ Find AlienHit and store HeliOS word CFA
  570.  
  571.  
  572.   \ *************************
  573.   \ Set up collision handlers
  574.   \ *************************
  575.  
  576.   : CREATE_COLLISIONS
  577.  
  578.   Bullet# 0
  579.   DO
  580.     GETCOLLHANDLER
  581.     DFLAG0= ERROR" Fail: Bullet CollHandler"
  582.     DDUP BulletCollHandlerTable I 4* + D!
  583.     BulletTable I 4* + D@  SpriteCtrl_CollHandler  INDEXD!L
  584.   LOOP
  585.  
  586.   GETCOLLHANDLER
  587.   DFLAG0= ERROR" Fail: Alien CollHandler"
  588.   DDUP AlienCollHandler D!
  589.   AlienAnim SpriteAnim_CollHandler  INDEXD!L
  590.   ;
  591.  
  592.   : FREE_COLLISIONS
  593.  
  594.   AlienCollHandler D@ FREECOLLHANDLER
  595.   Bullet# 0
  596.   DO
  597.     Bullet# 1- I - 4*
  598.     BulletCollHandlerTable +
  599.     D@ FREECOLLHANDLER
  600.   LOOP
  601.   ;
  602.  
  603.   \ *****************
  604.   \ Boundary routines
  605.   \ *****************
  606.  
  607.   \ Alien boundary sense routine
  608.  
  609.   : AlienBoundary
  610.  
  611.   SpriteCtrl_VisiHit INDEX@L                 \ Get boundary hit mask word
  612.   0 BTST                                     \ Did it hit left boundary
  613.   IF
  614.     AlienAnim SpriteAnim_UserData1 INDEX@L   \ Reverse X-motion
  615.     NEGATE
  616.     AlienAnim SpriteAnim_UserData1 INDEX!L
  617.   ELSE
  618.     1 BTST                                   \ Did it hit right boundary
  619.     IF
  620.       AlienAnim SpriteAnim_UserData1 INDEX@L \ Reverse X-motion
  621.       NEGATE
  622.       AlienAnim SpriteAnim_UserData1 INDEX!L
  623.     THEN
  624.   THEN
  625.  
  626.   2 BTST                                     \ Did it hit upper boundary
  627.   IF
  628.     DROP
  629.     AlienAnim SpriteAnim_UserData2 INDEX@L   \ Reverse Y-motion
  630.     NEGATE
  631.     AlienAnim SpriteAnim_UserData2 INDEX!L
  632.   ELSE
  633.     3 BTST                                   \ Did it hit lower boundary
  634.     IF
  635.       DROP
  636.       AlienAnim SpriteAnim_UserData2 INDEX@L \ Reverse Y-motion
  637.       NEGATE
  638.       AlienAnim SpriteAnim_UserData2 INDEX!L
  639.     ELSE
  640.       DROP
  641.     THEN
  642.   THEN
  643.   ;
  644.  
  645.   \ Remove Bullet - called when bullet hits boundary at edge of display
  646.  
  647.   : BulletRemove
  648.  
  649.   RemoveSprite
  650.   ;
  651.  
  652.   \ ****************************
  653.   \ User input response routines
  654.   \ ****************************
  655.  
  656.   : Fire
  657.  
  658.   RAWKEY @ 64 =
  659.   JOY1FIRE OR
  660.   IF
  661.     FireTimer @ 0<
  662.     IF
  663.       FiringRate FireTimer !
  664.       Bullet# 0
  665.       DO
  666.         BulletTable I 4* + D@ SETSTRUCTURE1
  667.         SpriteCtrl_Running STRUCTURE1 @L 0=
  668.         IF
  669.           1 SpriteCtrl_Running STRUCTURE1 !L
  670.           GunSpriteSet 8. D+ D@L SETSTRUCTURE2
  671.  
  672.           SpriteCtrl_XPos STRUCTURE2 @L 5 +
  673.           SpriteCtrl_XPos STRUCTURE1 !L
  674.  
  675.           SpriteCtrl_YPos STRUCTURE2 @L 2 -
  676.           SpriteCtrl_YPos STRUCTURE1 !L
  677.  
  678.           SpriteCtrl_UserData1 STRUCTURE1
  679.           SpriteCtrl_YAdd STRUCTURE1 D!L
  680.  
  681.           BulletSpeed NEGATE SpriteCtrl_UserData1 STRUCTURE1 !L
  682.  
  683.           1 SpriteCtrl_CollFlag STRUCTURE1 !L
  684.           1 SpriteCtrl_Flags STRUCTURE1 !L
  685.  
  686.           0. STRUCTURE1 INSTALLSPRITE
  687.           LEAVE
  688.         THEN
  689.       LOOP
  690.     ELSE
  691.       FireTimer DEC
  692.     THEN
  693.   THEN
  694.   ;
  695.  
  696.   : MoveGun
  697.  
  698.   RAWKEY @ 78 =
  699.   JOY1LEFTRIGHT 0>
  700.   OR
  701.   IF
  702.      GunSpeed
  703.      19 320
  704.      GunSpriteSet 8. D+ D@L SpriteCtrl_XPos D+
  705.      LIMIT+!L
  706.   ELSE
  707.     RAWKEY @ 79 =
  708.     JOY1LEFTRIGHT 0<
  709.     OR
  710.     IF
  711.      GunSpeed NEGATE
  712.      19 320
  713.      GunSpriteSet 8. D+ D@L SpriteCtrl_XPos D+
  714.      LIMIT+!L
  715.     THEN
  716.   THEN
  717.   ;
  718.  
  719.   \ ***********************************
  720.   \ Create sprite and animation objects
  721.   \ ***********************************
  722.  
  723.   : CREATE_SPRITES
  724.  
  725.   \ ----------
  726.   \ Gun sprite
  727.   \ ----------
  728.  
  729.   Slice1_BMap
  730.   154 272
  731.   13 15
  732.   1
  733.   MAKESPRITESET
  734.   DFLAG0= ERROR" Fail: Gun SpriteSet"
  735.   GunSpriteSet MAKEPOINTER
  736.  
  737.   GunSpriteSet 8. D+ D@L
  738.   DDUP  SpriteCtrl_XPos D+       170 -ROT !L
  739.         SpriteCtrl_YPos D+       239 -ROT !L
  740.  
  741.   Slice1_SliceControl   GunSpriteSet    INITSPRITESET
  742.  
  743.   \ -------------
  744.   \ Bullet sprite
  745.   \ -------------
  746.  
  747.   Slice1_BMap
  748.   159 279
  749.   3 7
  750.   1
  751.   MAKESPRITESET
  752.   DFLAG0= ERROR" Fail: Bullet SpriteSet"
  753.   BulletSpriteSet MAKEPOINTER
  754.  
  755.   Slice1_SliceControl   BulletSpriteSet    INITSPRITESET
  756.  
  757.   Bullet# 0
  758.   DO
  759.     BulletSpriteSet 8. D+ D@L CLONESPRITE
  760.     DFLAG0= ERROR" Fail: Bullet Sprite"
  761.     DDUP BulletTable I 4* + D!
  762.     SETSTRUCTURE1
  763.  
  764.     BulletCollTable        SpriteCtrl_CollTable      STRUCTURE1 D!L
  765.     BulletHitMask          SpriteCtrl_HitMask        STRUCTURE1 D!L
  766.     BulletMeMask           SpriteCtrl_MeMask         STRUCTURE1 D!L
  767.     -2                     SpriteCtrl_VisiZone       STRUCTURE1 !L
  768.     4                      SpriteCtrl_LeftZone       STRUCTURE1 !L
  769.     4                      SpriteCtrl_RightZone      STRUCTURE1 !L
  770.     4                      SpriteCtrl_UpZone         STRUCTURE1 !L
  771.     10                     SpriteCtrl_DownZone       STRUCTURE1 !L
  772.     ' BulletRemove CFA     SpriteCtrl_VisiForth      STRUCTURE1 !L
  773.   LOOP
  774.  
  775.   \ -------------
  776.   \ Alien sprites
  777.   \ -------------
  778.  
  779.   Slice1_BMap
  780.   24 276
  781.   14 9
  782.   9
  783.   MAKESPRITESET
  784.   DFLAG0= ERROR" Fail: Alien SpriteSet"
  785.   AlienSpriteSet MAKEPOINTER
  786.  
  787.   Slice1_SliceControl   AlienSpriteSet    INITSPRITESET
  788.  
  789.   \ ---------------
  790.   \ Alien animation
  791.   \ ---------------
  792.  
  793.   SpriteAnim_SIZEOF MAKESTRUCTURE
  794.   DFLAG0= ERROR" Fail: AlienAnim"
  795.   AlienAnim MAKEPOINTER
  796.  
  797.   AlienSpriteSet 8. D+  SpriteAnim_Image          AlienAnim    INDEXD!L
  798.   AlienCollTable        SpriteAnim_CollTable      AlienAnim    INDEXD!L
  799.   AlienHitMask          SpriteAnim_HitMask        AlienAnim    INDEXD!L
  800.   AlienMeMask           SpriteAnim_MeMask         AlienAnim    INDEXD!L
  801.   6                     SpriteAnim_AnimControl    AlienAnim    INDEX!L
  802.   1                     SpriteAnim_Skip           AlienAnim    INDEX!L
  803.   1                     SpriteAnim_VisiZone       AlienAnim    INDEX!L
  804.   4                     SpriteAnim_LeftZone       AlienAnim    INDEX!L
  805.   4                     SpriteAnim_RightZone      AlienAnim    INDEX!L
  806.   4                     SpriteAnim_UpZone         AlienAnim    INDEX!L
  807.   25                    SpriteAnim_DownZone       AlienAnim    INDEX!L
  808.   ' AlienBoundary CFA   SpriteAnim_VisiForth      AlienAnim    INDEX!L
  809.   SpriteAnim_UserData1 AlienAnim D+ SpriteAnim_XAdd  AlienAnim INDEXD!L
  810.   SpriteAnim_UserData2 AlienAnim D+ SpriteAnim_YAdd  AlienAnim INDEXD!L
  811.   ;
  812.  
  813.   : FREE_SPRITES
  814.  
  815.   AlienAnim       DDUP FREEMEMORY    CLEARPOINTER
  816.   AlienSpriteSet  DDUP FREESPRITESET CLEARPOINTER
  817.  
  818.   Bullet# 0
  819.   DO
  820.     Bullet# 1- I - 4* BulletTable +
  821.     DUP
  822.     D@ FREESPRITE
  823.     D0!
  824.   LOOP
  825.  
  826.   BulletSpriteSet DDUP FREESPRITESET CLEARPOINTER
  827.   GunSpriteSet    DDUP FREESPRITESET CLEARPOINTER
  828.   ;
  829.  
  830.   \ ****************
  831.   \ Re-Install Alien
  832.   \ ****************
  833.  
  834.   : ?Install_Alien
  835.  
  836.   SpriteAnim_Running AlienAnim INDEX@L 0=
  837.   IF
  838.     0                           SpriteAnim_CDForth     AlienAnim INDEX!L
  839.     0                           SpriteAnim_CountDown   AlienAnim INDEX!L
  840.     1                           SpriteAnim_Running     AlienAnim INDEX!L
  841.     1                           SpriteAnim_Flags       AlienAnim INDEX!L
  842.     1                           SpriteAnim_CollFlag    AlienAnim INDEX!L
  843.     280 RND 26 +                SpriteAnim_XPos        AlienAnim INDEX!L
  844.     36                          SpriteAnim_YPos        AlienAnim INDEX!L
  845.     0                           SpriteAnim_Current     AlienAnim INDEX!L
  846.     2                           SpriteAnim_Speed       AlienAnim INDEX!L
  847.     4                           SpriteAnim_Frames      AlienAnim INDEX!L
  848.     AlienMaxXSpeed RND 2 MAX 1 RND IF NEGATE THEN
  849.                                 SpriteAnim_UserData1   AlienAnim INDEX!L
  850.     AlienMaxYSpeed RND 1 MAX 1 RND IF NEGATE THEN
  851.                                 SpriteAnim_UserData2   AlienAnim INDEX!L
  852.     AlienAnim INSTALLSPRITEANIM
  853.   THEN
  854.   ;
  855.  
  856.   \ *********************
  857.   \ Close down everything
  858.   \ *********************
  859.  
  860.   : CLOSEDOWN
  861.  
  862.   FREE_COLLISIONS
  863.   FREE_SPRITES
  864.   FREE_COPPER
  865.   FREE_SLICECONTROL
  866.   FREE_DISPLAY
  867.   FREE_IMAGERY
  868.   FREE_RASINFO
  869.   FREE_DSLICES
  870.   RESETERROR"
  871.   ;
  872.  
  873.   LATESTCFA (CLOSEDOWN) !
  874.  
  875.   : TestDisplay          \ Start of program
  876.  
  877.   SCRCLR
  878.   CR
  879.  
  880.   ."        ********************************************************* "
  881.   CR 6 FPENSET
  882.   ."                         SIMPLE ANIMATION DEMO"
  883.   CR 1 FPENSET
  884.   ."        ********************************************************* "
  885.   CR
  886.   ."        This code demonstrates how to create a simple animation   "
  887.   CR
  888.   ."        in HeliOS."
  889.   CR
  890.   CR
  891.   ."        This builds upon the following Demos:"
  892.   CR
  893.   CR
  894.   ."        Demo1_SinglePF.src"
  895.   CR
  896.   ."        Demo2_SinglePFCopper.src"
  897.   CR
  898.   ."        Demo3_SimpleSprite.src"
  899.   CR
  900.   ."        Demo4_MultiSprites.src"
  901.   CR
  902.   ."        Demo5_MultiSptCollide.src"
  903.   CR
  904.   CR
  905.   ."        This code is then expanded in the following Demos:"
  906.   CR
  907.   CR
  908.   ."        Demo7_MultiAnim.src"
  909.   CR
  910.   ."        **********************************************************"
  911.   CR 6 FPENSET
  912.   ."                  Press <Space> or <L-Mouse> to see Demo"
  913.   CR 3 FPENSET
  914.   ."          Use a Joystick to move the gun turret and fire bullets"
  915.   CR
  916.   ."        **********************************************************"
  917.   CR
  918.  
  919.   WAITSPACE
  920.  
  921.   SCRCLR
  922.  
  923.   ERROR1 SETERROR"       \ Redirect system errors to our routine ERROR1
  924.  
  925.   CREATE_DSLICES
  926.   CREATE_RASINFO
  927.   CREATE_IMAGERY
  928.   CREATE_DISPLAY
  929.   CREATE_SLICECONTROL
  930.   CREATE_COPPER
  931.   CREATE_SPRITES
  932.   CREATE_COLLISIONS
  933.  
  934.   HeliOS_On
  935.  
  936.   GunSpriteSet 8. D+ D@L INSTALLSPRITE
  937.  
  938.   1 FrameRate !L
  939.  
  940.   Display1 SHOWDISPLAY
  941.  
  942.   BEGIN
  943.     WAITFRAME
  944.  
  945.     ?Install_Alien
  946.  
  947.     Fire
  948.  
  949.     MoveGun
  950.  
  951.     ?TERMINAL 27 =
  952.   UNTIL
  953.  
  954.   -3 AlienAnim SpriteAnim_Flags INDEX!L
  955.  
  956.   -3 GunSpriteSet 8. D+ D@L SpriteCtrl_Flags INDEX!L
  957.  
  958.   Bullet# 0
  959.   DO
  960.     -3 BulletTable I 4* + D@ SpriteCtrl_Flags INDEX!L
  961.   LOOP
  962.  
  963.   5 DELAY
  964.  
  965.   HeliOS_Off
  966.  
  967.   CLOSEDOWN
  968.   ;
  969.  
  970.   TestDisplay
  971.